package com.louis.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.louis.domain.User;
import com.louis.util.ListUtil;

/**
 * <p>
 * UserDetailsServiceImpl
 * </p>
 * 
 * @author: louisjiang
 * @version: 1.0.0,Apr 23, 20126:07:45 PM
 */

@Service("userService")
public class UserDetailsServiceImpl extends GeneralServiceImpl implements UserDetailsService, GeneralService {

	/**
	 * @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
	 */
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("username", username);
		List<User> userList = getGeneralDao().query(User.class, "from User u where u.username=:username", map);
		return ListUtil.isEmpty(userList) ?null: userList.get(0);
	}
}
